package com.auto.survey.activity.monitoring.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.auto.survey.activity.monitoring.entity.Point
import kotlinx.coroutines.flow.Flow

@Dao
interface PointDao {

    /**
     * 根据监测对象ID获取测点列表，按测量顺序排序
     * @param objectId 监测对象ID
     * @return 测点列表Flow流
     */
    @Query("SELECT * FROM Point WHERE monitoringObjectId = :objectId")
    fun getPointsByObjectId(objectId: Int): Flow<List<Point>>

    @Query("SELECT * FROM Point WHERE monitoringObjectId = :objectId AND pointType = :pintType")
    fun getPointsByObjectIdAndType(objectId: Int, pintType:String): Flow<List<Point>>

    /**
     * 插入新测点
     * @param point 测点实体
     * @return 插入的测点ID
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertPoint(point: Point): Long

    /**
     * 批量插入测点
     * @param points 测点列表
     * @return 插入的测点ID列表
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertPoints(points: List<Point>): List<Long>

    /**
     * 更新测点信息
     * @param point 测点实体
     */
    @Update
    suspend fun updatePoint(point: Point)

    /**
     * 删除测点
     * @param point 测点实体
     */
    @Delete
    suspend fun deletePoint(point: Point)

    /**
     * 根据测点ID删除测点
     * @param id 测点ID
     */
    @Query("DELETE FROM Point WHERE id = :id")
    suspend fun deletePointById(id: Int)
}